package net.uhuijia.zb.userzhubolive.controller;

import net.uhuijia.enums.MoreInfo;
import net.uhuijia.user.usermall.persistence.model.UserMall;
import net.uhuijia.utils.IticConst;
import net.uhuijia.vo.ResultMapVo;
import net.uhuijia.vo.ReturnListVo;
import net.uhuijia.vo.zb.UserZhuboListVo;
import net.uhuijia.vo.zb.ZbDetailVo;
import net.uhuijia.zb.userzhubolive.persistence.model.UserZhuboLive;
import net.uhuijia.zb.userzhubolive.persistence.model.UserZhuboLiveExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.zb.userzhubolive.service.UserZhuboLiveService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping(value="/userzhubolive")
public class UserZhuboLiveController
     extends BaseController<UserZhuboLiveService,UserZhuboLive,UserZhuboLiveExample >{
    @Autowired
    private UserZhuboLiveService userZhuboLiveService;

    /**
     * 查询首页直播列表
     * @return
     */
    @RequestMapping(value = "/zbLiveList", method = RequestMethod.GET)
    @ResponseBody
    public ResultMapVo<ReturnListVo> zbLiveList(HttpServletRequest request) {
        UserZhuboLiveExample example = new UserZhuboLiveExample();
        IticConst.handlePageQueryDefault(request,example);
        List<UserZhuboLive> userZhuboLives = this.userZhuboLiveService.findUserZhuBoLiveByPage(example);
        List<UserZhuboListVo> userZhuboListVos = new ArrayList<>();
        for(UserZhuboLive userZhuboLive : userZhuboLives){
            //将直播列表转换成Vo
            UserZhuboListVo userZhuboListVo = this.userZhuboLiveService.userZhuboLiveWrapUserZhuboListVo(userZhuboLive);
            userZhuboListVos.add(userZhuboListVo);
        }
        int count = this.userZhuboLiveService.findUserZhuBoLiveCount(example);
        MoreInfo moreInfo = IticConst.isMore(request,count);
        ReturnListVo<UserZhuboListVo> returnListVo = new ReturnListVo<>(userZhuboListVos,count, moreInfo);
        return ResultMapVo.ok(returnListVo);
    }

    /**
     * 主播详情页基本信息
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ResponseBody
    public ResultMapVo<ZbDetailVo> zbDetail(String liveId){
        UserMall userMall = this.getUserMallByTokenAndDevice();
        ZbDetailVo zbDetailVo = this.userZhuboLiveService.zbOnlineDetail(userMall,liveId);
        return ResultMapVo.ok(zbDetailVo);
    }






}